//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package nccloud.web.obm.ebankdfgz.action;

import java.util.ArrayList;
import nc.itf.obm.ebank.IObmEbankNccService;
import nc.itf.obm.payroll.IEbankdfgzMaintain;
import nc.vo.obm.payroll.DfgzBVO;
import nc.vo.obm.payroll.DfgzBillVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.CircularlyAccessibleValueObject;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pub.lang.UFDouble;
import nccloud.framework.core.exception.ExceptionUtils;
import nccloud.framework.service.ServiceLocator;
import nccloud.framework.web.action.itf.ICommonAction;
import nccloud.framework.web.container.IRequest;
import nccloud.framework.web.container.SessionContext;
import nccloud.framework.web.convert.translate.Translator;
import nccloud.framework.web.processor.template.BillCardConvertProcessor;
import nccloud.framework.web.ui.pattern.billcard.BillCard;
import nccloud.framework.web.ui.pattern.billcard.BillCardOperator;

public class EbankDfgzInsertAction implements ICommonAction {
    public EbankDfgzInsertAction() {
    }

    public Object doAction(IRequest request) {
        BillCard result = null;
        BillCardOperator operator = new BillCardOperator();
        DfgzBillVO vo = (DfgzBillVO)operator.toBill(request);
        String pk_user = SessionContext.getInstance().getClientInfo().getUserid();
        String pk_org = null;
        String pk_group = null;

        try {
            DfgzBillVO[] vos = new DfgzBillVO[]{vo};

            for(int i = 0; i < vos.length; ++i) {
                pk_org = vos[i].getParentVO().getPk_org();
                pk_group = vos[i].getParentVO().getPk_group();
                vos[i].getParentVO().setPk_dfgz((String)null);
                vos[i].getParentVO().setVbillno((String)null);
                vos[i].getParentVO().setVbillstatus(-1);
                vos[i].getParentVO().setModifier((String)null);
                vos[i].getParentVO().setModifiedtime((UFDateTime)null);
                vos[i].getParentVO().setSubmitdate((UFDate)null);
                vos[i].getParentVO().setSubmiter((String)null);
                vos[i].getParentVO().setSubmittime((UFDateTime)null);
                vos[i].getParentVO().setApprovedate((UFDate)null);
                vos[i].getParentVO().setApprovenote((String)null);
                vos[i].getParentVO().setApprover((String)null);
                vos[i].getParentVO().setApprovetime((UFDateTime)null);
                vos[i].getParentVO().setGensrc((String)null);
                vos[i].getParentVO().setTs((UFDateTime)null);
                vos[i].getParentVO().setYurref((String)null);
                double totalmoney = 0.0;
                vos[i].getParentVO().setStatus(2);
                DfgzBVO[] bodyvos = (DfgzBVO[])((DfgzBVO[])vos[i].getChildrenVO());
                ArrayList<DfgzBVO> aggVOList = new ArrayList();

                for(int j = 0; j < bodyvos.length; ++j) {
                    bodyvos[j].setPk_dfgz((String)null);
                    bodyvos[j].setPk_dfgz_b((String)null);
                    bodyvos[j].setTs((UFDateTime)null);
                    bodyvos[j].setPk_group(pk_group);
                    bodyvos[j].setPk_org(pk_org);
                    totalmoney += bodyvos[i].getAmount().doubleValue();
                    if (bodyvos[j].getStatus() != 3) {
                        aggVOList.add(bodyvos[j]);
                    }
                }

                vos[i].setChildrenVO((CircularlyAccessibleValueObject[])aggVOList.toArray(new DfgzBVO[0]));
                vos[i].getParentVO().setBillmaker(pk_user);
                vos[i].getParentVO().setBillmakedate(new UFDate());
                vos[i].getParentVO().setCreator(pk_user);
                vos[i].getParentVO().setPersontotal(bodyvos.length);
                vos[i].getParentVO().setPaytotalnum(new UFDouble(totalmoney));
            }

            IObmEbankNccService serviceNcc = (IObmEbankNccService)ServiceLocator.find(IObmEbankNccService.class);
            serviceNcc.dfgzApproveSignWithClient(pk_user, vos);
            IEbankdfgzMaintain service = (IEbankdfgzMaintain)ServiceLocator.find(IEbankdfgzMaintain.class);
            DfgzBillVO[] newvos = service.insert(vos);
            BillCardConvertProcessor processor = new BillCardConvertProcessor();
            result = processor.convert("3610PAYR_C01", newvos[0]);
            Translator translator = new Translator();
            translator.translate(result);
        } catch (BusinessException var15) {
            ExceptionUtils.wrapException(var15);
        } catch (Exception var16) {
            ExceptionUtils.wrapException(var16);
        }

        return result;
    }
}
